package cn.stylefeng.guns.modular.demo.controller;


import cn.stylefeng.guns.dao.entity.Store;
import cn.stylefeng.guns.dao.entity.Supplier;
import cn.stylefeng.guns.dao.service.IStoreService;
import cn.stylefeng.guns.modular.demo.controller.domain.QueryStoreRequest;
import cn.stylefeng.guns.modular.demo.controller.domain.QuerySupplierRequest;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author quspacedraon
 * @since 2024-02-20
 */
@RestController
@ApiResource(name = "门店", resBizType = ResBizTypeEnum.BUSINESS, path = "/store")
public class StoreController {
    @Resource
    private IStoreService storeService;

    @PostResource(name = "门店列表", path = "/list", requiredLogin = true, requiredPermission = true)
    @ApiOperation("查询门店列表")
    public ResponseData<PageResult<Store>> list(@RequestBody QueryStoreRequest queryStoreRequest) {

        Page<Store> page = new Page<>();
        page.setCurrent(queryStoreRequest.getPageNo());
        page.setSize(queryStoreRequest.getPageSize());
        LambdaQueryWrapper<Store> lambdaQueryWrapper = Wrappers.<Store>lambdaQuery()
                .eq(StringUtils.isNotBlank(queryStoreRequest.getStoreCode()), Store::getStoreCode, queryStoreRequest.getStoreCode())
                .like(StringUtils.isNotBlank(queryStoreRequest.getName()), Store::getStoreName, queryStoreRequest.getName()
                );
        Page<Store> page1 = storeService.page(page, lambdaQueryWrapper);
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page1));
    }

}
